//
//  DoubleClickExampleAppDelegate.m
//  Google Ads iPhone publisher SDK.
//
//  Copyright Google Inc 2009. All rights reserved.
//

#import "DoubleClickExampleAppDelegate.h"

@implementation DoubleClickExampleAppDelegate

@synthesize window = window_;
@synthesize mainViewController = mainViewController_;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
  UIView *mainView = [mainViewController_ view];
  [window_ addSubview:mainView];

  adViewController_ = [[GADAdViewController alloc] initWithDelegate:self];
  adViewController_.adSize = kGADAdSize320x50;

  // ***************************************************************************
  // Please replace kGADDoubleClickKeyname based on your DFP configuration.
  // ***************************************************************************
  NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                              @"sdktest/testing;kw=test",
                              kGADDoubleClickKeyname,
                              nil];
  [adViewController_ loadGoogleAd:attributes];

  // Position ad at bottom of screen.
  UIView *adView = adViewController_.view;
  CGFloat adViewHeight = [adView bounds].size.height;
  CGRect bounds = [mainView bounds];
  CGPoint center = CGPointMake(CGRectGetMidX(bounds),
                               CGRectGetMaxY(bounds) - adViewHeight / 2);
  [adView setCenter:center];
  [mainView addSubview:adView];
  [window_ makeKeyAndVisible];
}

- (void)dealloc {
  [adViewController_ release];
  [window_ release];
  [super dealloc];
}

- (UIViewController *)viewControllerForModalPresentation:
    (GADAdViewController *)adController {
  return mainViewController_;
}

// Set the ad click action to display the advertiser's site in a full-screen
// UIWebView.
- (GADAdClickAction)adControllerActionModelForAdClick:
    (GADAdViewController *)adController {
  return GAD_ACTION_DISPLAY_INTERNAL_WEBSITE_VIEW;
}

- (void)loadSucceeded:(GADAdViewController *)adController
          withResults:(NSDictionary *)results {
  // Successful load. You can examine the results for interesting things.
  NSLog(@"Load Succeeded: %@", results);
}

- (void)loadFailed:(GADAdViewController *)adController
         withError:(NSError *) error {
  // Handle error here.
}

@end


